package com.test;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TicketSale {
	public static void main(String[] args) {
		long start =System.currentTimeMillis();		
		ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 10, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
		for (int i = 5; i >0 ; --i) {
			new Thread(()->{
				while(true){
					 int saleTicket = TicketSource.saleTicket();
				     sleepMethod();
					 if (saleTicket ==0) {
						System.out.println("票卖完了");
						break;	
					}
				}
				
			}	
		   ,"0"+i+"窗口").start();
		}
		long end  =System.currentTimeMillis();
		System.out.println("用时 ：" + (end- start) + " ms" );
	}
	
	
	public static void sleepMethod(){
		try {
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
